﻿@model List<DHQGHN.PM2.Models.HouseHoldModel>
@functions{
    public string GetAntiForgeryToken()
    {
        string cookieToken, formToken;
        AntiForgery.GetTokens(null, out cookieToken, out formToken);
        return cookieToken + "," + formToken;
    }
}
<script>
    var HOUSEHOLD_NUMBER = "";
    var HOUSEHOLD_NAME = "";
    var NUM_OF_HH_MEMBER = "";
    var AREA_ID = "";
    var ADDRESS_ID = "";
    var SURVEY_METHOD_ID = "";

    function onDelete(id) {
        // alert(id);
        $("#divLoading").show();
        $.ajax({
            // url: "/admin/thongbao/delete.do?id=" + id,
            url: '@Url.Action("DeleteHouseHold")',
            data: {
                "HOUSEHOLD_ID": id
            },
            type: 'GET',
            success: function (data) {
                $("#divLoading").hide();
                bootbox.dialog({
                    title: "Bạn có chắc chắn xóa bản kê này không?",
                    message: data,
                    buttons: {
                        success: {
                            label: "<i class='fa fa-warning'></i> Xóa",
                            className: "btn btn-sm btn-danger", //btn-success
                            callback: function () {
                                //alert(id);
                                $("#divLoading").show();
                                $.ajax({
                                    url: "@Url.Action("DeleteHouseHoldConfirmed")",
                                    data: { "HOUSEHOLD_ID": id },
                                    //dataType: 'json',
                                    type: 'post',
                                    headers: {
                                        'VerificationToken': '@GetAntiForgeryToken()'
                                    },
                                    success: function (d) {
                                        $("#divLoading").hide();
                                        window.location.reload(true);
                                        Layout.toastr("", "Xóa thành công");
                                        //if (!d.success) Metronic.showMessage('Thông báo', 'Báº¡n khĂ´ng cĂ³ quyá»n thá»±c hiá»‡n chá»©c nÄƒng nĂ y.', 'OK');
                                        ///Thongbao.grid.getDataTable().ajax.reload();
                                    },
                                    error: function (ex) {
                                        alert(JSON.stringify(ex));
                                    }
                                });

                            }
                        },
                        danger: {
                            label: "<i class='fa fa-reply'></i> Hủy bỏ",
                            className: "btn btn-sm btn-default",//"btn-danger",
                            callback: function () {
                            }
                        }
                    }
                });
            }
        });
        return false;
    }
    $(document).ready(function () {
        $('[data-toggle="tooltip"]').tooltip();
        $("#inExcel").click(function () {
            var searchInfo = getSearchInfo();
            var straction = '@Url.Action("ExportData", "HouseHold")';
            window.location.href = straction + '?HOUSEHOLD_NUMBER=' + searchInfo.HOUSEHOLD_NUMBER +
                '&HOUSEHOLD_NAME=' + searchInfo.HOUSEHOLD_NAME +
                '&NUM_OF_HH_MEMBER=' + searchInfo.NUM_OF_HH_MEMBER +
                '&AREA_ID=' + searchInfo.AREA_ID +
                '&ADDRESS_ID=' + searchInfo.ADDRESS_ID +
                '&SURVEY_METHOD_ID=' + searchInfo.SURVEY_METHOD_ID;
        });

        $("#btnPrint").click(function () {
            var searchInfo = getSearchInfo();
            var straction = '@Url.Action("print", "HouseHold")';
            var frame = $('<iframe src="' + straction + '?HOUSEHOLD_NUMBER=' + searchInfo.HOUSEHOLD_NUMBER +
                '&HOUSEHOLD_NAME=' + searchInfo.HOUSEHOLD_NAME +
                '&NUM_OF_HH_MEMBER=' + searchInfo.NUM_OF_HH_MEMBER +
                '&AREA_ID=' + searchInfo.AREA_ID +
                '&ADDRESS_ID=' + searchInfo.ADDRESS_ID +
                '&SURVEY_METHOD_ID=' + searchInfo.SURVEY_METHOD_ID + '" frameborder="0"></iframe>');
            $('#divPrintHHPV').html(frame);
            return false;
        });
    });

    function getSearchInfo() {

        return {
            HOUSEHOLD_NUMBER: $("#householdNumber_store").val(),
            HOUSEHOLD_NAME: $("#householdName_store").val(),
            NUM_OF_HH_MEMBER: $("#numofhhMember_store").val(),
            AREA_ID: $("#areaId_store").val(),
            ADDRESS_ID: $("#addressId_store").val(),
            SURVEY_METHOD_ID: $("#surveyMothodId_store").val(),
        };
    }
</script>
@{
    ViewBag.Title = "Quản lý bảng kê";
    ViewBag.Group = "Lập bảng kê";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

@{
    var grid = new WebGrid(canPage: true, rowsPerPage: 10, selectionFieldName: "selectedRow");
    if (Model.Count == 0)
    {
        grid.Bind(@Model, autoSortAndPage: false, rowCount: 0);
    }
    else
    {
        grid.Bind(@Model, autoSortAndPage: false, rowCount: Model[0].RECODE_COUNT);
    }
    grid.Pager(WebGridPagerModes.NextPrevious);
}

@Html.Hidden("householdName_store", ViewData["householdName"])
@Html.Hidden("numofhhMember_store", ViewData["numofhhMember"])
@Html.Hidden("addressId_store", ViewData["addressId"])
@Html.Hidden("householdNumber_store", ViewData["householdNumber"])
@Html.Hidden("areaId_store", ViewData["areaId"])
@Html.Hidden("surveyMothodId_store", ViewData["surveyId"])
<div class="page-bar">
    <ul class="page-breadcrumb" style="padding: 4px;">
        <li>
            <i class="fa fa-home"></i>
            <a href="#"> Quản lý bảng kê</a>
        </li>
    </ul>
</div>
@using (Html.BeginForm("IndexHouseHoldPV", "HouseHold", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <div class="row" style="margin-top:5px;">
        <fieldset id="fs1" class="">
            <div id="d1" class="col-md-6" style="">
                @*<div class="row"  style="margin-top:5px;">
                        <div class="col-md-4">
                            @Html.Label("Mã hộ", new { @class = "text-center" })
                        </div>
                        <div class="col-md-8">
                            @Html.TextBox("HOUSEHOLD_CODE", "", new { @class = "form-control ", placeholder = "Tìm theo mã hộ", style = "  " })
                        </div>
                    </div>*@
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4">
                        @Html.Label("Đơn vị hành chính", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8">
                        @ViewBag.ADM_UNIT
                    </div>
                </div>

                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4">
                        @Html.Label("Tên chủ hộ", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8">
                        @Html.TextBox("HOUSEHOLD_NAME", "", new { @class = "form-control  input-sm", placeholder = "Tìm theo tên chủ hộ", style = "  ", maxlength = 255 })
                    </div>
                </div>

                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4">
                        @Html.Label("Số người trong hộ", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8 ">
                        @Html.TextBox("NUM_OF_HH_MEMBER", "", new { @class = "form-control  input-sm", placeholder = "Tìm theo số người trong hộ", style = "" })
                    </div>
                </div>

                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4">
                        @Html.Label("Địa chỉ chi tiết", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8">
                        @Html.DropDownList("ADDRESS_ID", ViewBag.Address as List<SelectListItem>, "Tìm theo địa chỉ chi tiết", new { @class = "form-control input-sm", style = " " })
                    </div>
                </div>
            </div>

            <div id="d2" class="col-md-6">
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4">
                        @Html.Label("Số hộ", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8 ">
                        @Html.TextBox("HOUSEHOLD_NUMBER", "", new { @class = "form-control  input-sm", placeholder = "Tìm theo số hộ", style = " " })
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4">
                        @Html.Label("Địa bàn điều tra", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8">
                        @Html.DropDownList("AREA_ID", ViewBag.Area as List<SelectListItem>, "Tìm theo địa bàn", new { @class = "form-control input-sm", style = " " })
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-4 ">
                        @Html.Label("Phương thức điều tra", new { @class = "text-center" })
                    </div>
                    <div class="col-md-8">
                        @Html.DropDownList("SURVEY_METHOD_ID", ViewBag.SurveyMethod as List<SelectListItem>, "Tìm theo phương thức điều tra", new { @class = "form-control input-sm", style = " " })
                    </div>
                </div>
                <div class="row pull-right" style="margin-top:5px; margin-bottom:5px;">
                    <div class="col-md-12">
                        <button id="btnSearch" type="submit" class="btn btn-sm btn-default btn_search_household"><i class="fa fa-search"></i> Tìm Kiếm</button>
                        <button type="button" class="btn btn-sm btn-default btn_search_household" onclick="window.location.href='@Url.Action("LapBangKeVM")';"><i class="fa  fa-plus-square-o"></i> Tạo mới</button>
                        <button id="inExcel" type="button" class="btn btn-sm btn-default btn_search_household"><i class="fa fa-file-excel-o"></i> Xuất Excel</button>
                        <button id="btnPrint" class="btn btn-sm btn-default btn_search_household"><i class="fa fa-print"></i> In</button>
                        <div id="divPrintHHPV" style="display:none;"></div>
                    </div>
                </div>
            </div>

        </fieldset>
    </div>

}

<div id="gridContent" align="center">
    @if (Model.Count > 0)
    {
        if (Model.First().RECODE_COUNT <= 10)
        {
            <script>
                $(document).ready(function () {
                    $('.grid-footer').empty();
                    $('#HouseholdGrid').append('<tfoot><tr class = "grid-footer"><td colspan="8"></td></tr></tfoot>')
                })
            </script>
        }
        <script>
            $(document).ready(function () {
                $('.grid-footer td').append('<div style="float:right;">Đang xem ' + '@Model.First().RowNumber' + ' - ' + '@Model.Last().RowNumber' + ' trên ' + '@Model.First().RECODE_COUNT' + ' bản ghi</div>')
            })
        </script>
        @grid.GetHtml(tableStyle: "table table-striped table-bordered table-hover dataTable no-footer", headerStyle: "header", htmlAttributes: new { id = "HouseholdGrid" }, alternatingRowStyle: "alt", selectedRowStyle: "select", rowStyle: "webgrid-row-style",
                  footerStyle: "grid-footer",
                  mode: WebGridPagerModes.All,
                  firstText: "|<<",
                  previousText: "|<",
                  nextText: ">|",
                  lastText: ">>|",

                       columns: grid.Columns(
                  grid.Column(
                                 columnName: "STT",
                                 header: "STT",
                                 format: @<text>
                                    <span id="spnSTT" class="display-mode">@item.RowNumber</span>
                                </text>,
                                 canSort: false,
                                 style: "clsSTT"
                               ),
                            @*grid.Column("HOUSEHOLD_CODE", "Mã hộ", format:
                                @<text>
                                    <span id="spnHouseHoldCode" class="display-mode">@item.HOUSEHOLD_CODE</span>
                                </text>,canSort: false),*@

 grid.Column("HOUSEHOLD_NUMBER", "Số hộ", format:
@<text>
    <span id="spnHouseHoldNumber" class="display-mode">@item.HOUSEHOLD_NUMBER</span>
</text>,canSort: false, style: "clsHOUSEHOLD_NUMBER hidden-480"),

                grid.Column("HOUSEHOLD_NAME", "Tên chủ hộ", format:
                @<text>
                    <div id="spnHouseHoldName" class="hidden-880">@item.HOUSEHOLD_NAME</div>
                    <div class="display-880"><b>@item.HOUSEHOLD_NAME</b></div>
                    <div class="display-480">Số hộ: @item.HOUSEHOLD_NUMBER</div>
                    <div class="display-580">Địa bàn: @item.AREA_ID_NAME</div>
                    <div class="display-680">Số nhân khẩu: @item.NUM_OF_HH_MEMBER</div>
                    <div class="display-780">Phương thức ĐT: @item.SURVEY_METHOD_NAME</div>
                    <div class="display-880">Địa chỉ: @item.ADDRESS_ID_NAME</div>
                </text>,canSort: false),

                grid.Column("AREA_ID_NAME", "Địa bàn điều tra", format:
                @<text>
                    <span id="spnAREA_ID_NAME" class="display-mode">@item.AREA_ID_NAME</span>
                </text>,canSort: false, style:"hidden-580"),

                grid.Column("NUM_OF_HH_MEMBER", "Số nhân khẩu",  format:
                @<text>
                    <span id="spnNumOfHouseHoldNumber">@item.NUM_OF_HH_MEMBER</span>
                </text>,canSort: false, style:"hidden-680"),

                grid.Column("SURVEY_METHOD_NAME", "Phương thức ĐT", format:
                @<text>
                    <span id="spnSURVEY_METHOD_NAME" class="display-mode">@item.SURVEY_METHOD_NAME</span>
                </text>,canSort: false, style:"hidden-780"),

                grid.Column("ADDRESS_ID_NAME", "Địa chỉ chi tiết", format:
                @<text>
                    <span id="spnADDRESS_ID_NAME" class="display-mode">@item.ADDRESS_ID_NAME</span>
                </text>,canSort: false, style:"hidden-880 autohidden"),

                grid.Column("#", format:
                @<text>
                    <div style="text-align:center;">
                        <div class="btn-group">
                            <a href="#" data-toggle="dropdown" class="btn btn-lg" style="margin:0px; padding:0px;">
                                <div class="label label-info">
                                    <i class="fa fa-th"></i>
                                </div>
                            </a>
                            <ul class="dropdown-menu no-angle pull-right right">
                                <li>
                                    <a href="@Url.Action("DetailHouseHold", "HouseHold", new { item.HOUSEHOLD_ID })"><i class="fa fa-eye"></i> Xem bảng kê</a>
                                </li>
                                <li>
                                    <a href="@Url.Action("SuaBangKeVM", "HouseHold", new { item.HOUSEHOLD_ID })"><i class="fa fa-pencil"></i> Cập nhật bảng kê</a>
                                </li>
                                <li>
                                    <a onclick="onDelete('@item.HOUSEHOLD_ID')" data-index="@item.HOUSEHOLD_ID" style="cursor:pointer;"> <i class="fa fa-trash-o"></i> Xóa bảng kê</a>
                                    @*<a href="@Url.Action("DeleteHouseHold", "HouseHold", new { item.HOUSEHOLD_ID })"><i class="fa fa-trash-o"></i> Xóa bảng kê</a>*@
                                </li>
                            </ul>
                        </div>
                    </div>
                </text>, canSort: false, style: "action")

                                  )
                              )
        <script type="text/javascript">
            $(function () {

                $('.clsSTT').css('text-align', 'center').css('width', '30px');
                $('.clsHOUSEHOLD_NUMBER').css('text-align', 'center').css('width', '60px');

                $('.clsAREA_CODE').css('text-align', 'center');
                var colsHeader = $('#gridContent th');
                $(colsHeader[0]).addClass('hidden-480').css('text-align', 'center');
                $(colsHeader[1]).addClass('hidden-480').css('text-align', 'center');
                $(colsHeader[2]).addClass('hidden-480').css('text-align', 'center');
                $(colsHeader[3]).addClass('hidden-580').css('text-align', 'center');
                $(colsHeader[4]).addClass('hidden-680').css('text-align', 'center');
                $(colsHeader[5]).addClass('hidden-780').css('text-align', 'center');
                $(colsHeader[6]).addClass('hidden-880').css('text-align', 'center');
                $(colsHeader[7]).css('text-align', 'center').css('width', '50px');
            });
        </script>
    }
    else
    {
        <div align="center"><h4>Không tìm thấy kết quả nào phù hợp</h4></div>
    }
    <br /><br /><br />
</div>
